import { SignJWT, jwtVerify } from 'jose';
const secret = new TextEncoder().encode(
    'cc7e0d44fd473002f1c42167459001140ec6389b7353f8088f4d9a95f2f596f2',
)
const alg = 'HS256'

const jwt = await new SignJWT({ 'urn:example:claim': true, user_id: 123456 })
    .setProtectedHeader({ alg })
    .setIssuedAt()
    .setIssuer('urn:example:issuer')
    .setAudience('urn:example:audience')
    .setExpirationTime('1s')
    .sign(secret)
setTimeout(async () => {
    try {
        const { payload } = await jwtVerify(jwt, secret);
        console.log('Decoded Payload:', payload);

        // 获取user_id
        const userId = payload.user_id;
        console.log('User ID:', userId);
    } catch (error) {
        console.error('Error verifying JWT:', error);
        if (error.code === 'ERR_JWT_EXPIRED') {
            console.log('JWT has expired.');
        }
    }
}, 2000)

